import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

import * as bodyParser from 'body-parser';
import { AppModule } from './app.module';
import { ApiValidationPipe } from './pipe/validate';
import { HttpExceptionFilter } from './filter/catch';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle('DEX.IO CMS Api')
    .setDescription('The DEX.io CMS API Docs')
    .setVersion('1.0')
    .addBearerAuth({
      type: 'http',
    })
    .addTag('blog', '博客相关api')
    .addTag('contact', '联系我们相关api')
    .addTag('file', '文件相关api')
    .addTag('dictionary', '数据字典相关api')
    .addTag('locales', '页面国际化相关api')
    .addTag('subscribe', '用户订阅相关api')
    .addTag('user', '后台用户相关api')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);

  app.enableCors();

  app.use(
    bodyParser.urlencoded({
      limit: '5MB',
      extended: true,
    }),
  );
  app.useGlobalPipes(new ApiValidationPipe());
  app.useGlobalFilters(new HttpExceptionFilter());

  await app.listen(3000);
}
bootstrap();
